package biznussoft.fieldservice360.dialogfragments;

import biznussoft.fieldservice360.R;
import biznussoft.fieldservice360.listeners.DialogListener;
import biznussoft.fieldservice360.utils.Session;


import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;

public class DatePickerDialogFragment  extends DialogFragment{
	
	private DialogListener listener;
	private Dialog dialog;
	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		listener = (DialogListener) getActivity();
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		//setStyle(STYLE_NO_FRAME, android.R.style.Theme_Holo_Light);
	}

	 public static DialogFragment newInstace() {
	        DialogFragment dialogFragment = new DatePickerDialogFragment();
	        return dialogFragment;
	    }
	 
	    @Override
	    public Dialog onCreateDialog(Bundle savedInstanceState) {


	    	dialog = new Dialog(getActivity());
	    	dialog.setTitle("Select Time");                                                
	    	dialog.setContentView(R.layout.datapickerdialog);
	    	//	         dialog.getWindow().setLayout(screenWidth, screenHeight);
	    	dialog.show();
	    	final DatePicker picker = (DatePicker) dialog.findViewById(R.id.dateEdit);


	    	Button next = (Button) dialog.findViewById(R.id.btNext);
	    	next.setOnClickListener(new OnClickListener() {

	    		@Override
	    		public void onClick(View v) {
	    			Session.sb.delete(0, Session.sb.length());
	    			Session.sb.append(picker.getYear()).append("-").append(picker.getMonth()).append("-").append(picker.getDayOfMonth());
	    			Log.i("TPT","Date  is   :"+picker.getYear()+"-"+picker.getMonth()+"-"+picker.getDayOfMonth());
	    			listener.nextDialog("time");
	    			dialog.dismiss();
	    		}
	    	});

	    	return dialog;
	    }
	 
	    
}
